﻿<UserControl x:Class="HouseKeepingPL.UserControls.Outcomes"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             Name="OutcomesUserControl"
             Width="auto"
             d:DesignHeight="321"
             d:DesignWidth="511"
             DataContext="{Binding OutcomesVM,
                                   Source={StaticResource Locator}}"
             mc:Ignorable="d">

    <UserControl.Resources>
        <ControlTemplate x:Key="validationTemplate">
            <DockPanel>
                <Border BorderBrush="Red" BorderThickness="1">
                    <AdornedElementPlaceholder />
                </Border>
                <Border Width="20"
                        Height="20"
                        Margin="5,0,0,0"
                        Background="Red"
                        CornerRadius="10"
                        DockPanel.Dock="right"
                        ToolTip="{Binding ElementName=customAdorner,
                                          Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">
                    <TextBlock HorizontalAlignment="center"
                               VerticalAlignment="center"
                               FontSize="20"
                               FontWeight="Bold"
                               Foreground="WhiteSmoke">
                        !!
                    </TextBlock>
                </Border>
            </DockPanel>
        </ControlTemplate>
        <Style x:Key="MyTabStyle" TargetType="Grid">
            <Setter Property="Background" Value="AliceBlue" />
        </Style>

        <Style x:Key="textBoxInError" TargetType="{x:Type TextBox}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="PasswordBoxInError" TargetType="{x:Type PasswordBox}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="ComboBoxInError" TargetType="{x:Type ComboBox}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
                </Trigger>
            </Style.Triggers>
        </Style>

    </UserControl.Resources>



    <Grid Style="{StaticResource MyTabStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="9*" />
            <RowDefinition Height="*" />
            <RowDefinition Height="5*" />
        </Grid.RowDefinitions>
        <DataGrid Grid.Row="0"
                  Margin="10"
                  VerticalAlignment="Top"
                  AutoGenerateColumns="False"
                  CanUserAddRows="False"
                  CanUserDeleteRows="False"
                  DockPanel.Dock="Top"
                  ItemsSource="{Binding Path=GetOutcomes,
                                        Mode=OneWay}"
                  SelectedItem="{Binding Path=CurrentlySelectedOutcome,
                                         Mode=TwoWay}"
                  SelectionMode="Single">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Path=Date,
                                                      ConverterCulture=he-IL,
                                                      Mode=TwoWay}"
                                    Header="Date Of Action"
                                    IsReadOnly="True" />
                <DataGridTextColumn Binding="{Binding Path=Amount,
                                                      Mode=TwoWay}"
                                    Header="Amount"
                                    IsReadOnly="True" />
                <DataGridTextColumn Binding="{Binding Path=ActionTypeId,
                                                      Mode=TwoWay}"
                                    Header="Type Of Action"
                                    IsReadOnly="True" />
                <DataGridTextColumn Binding="{Binding Path=Comment,
                                                      Mode=TwoWay}"
                                    Header="Comment"
                                    IsReadOnly="True" />
            </DataGrid.Columns>

        </DataGrid>
        <GridSplitter Grid.Row="1"
                      Grid.Column="2"
                      Width="auto"
                      Height="1"
                      Margin="0"
                      HorizontalAlignment="Stretch"
                      VerticalAlignment="Stretch"
                      Background="#FF3164a5"
                      ResizeDirection="Rows" />

        <Grid Grid.Row="2" Margin="0,0,6,0">

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="64*" />
                <ColumnDefinition Width="128*" />
                <ColumnDefinition Width="128*" />
                <ColumnDefinition Width="128*" />
                <ColumnDefinition Width="128*" />
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Row="0"
                       Grid.Column="0"
                       Margin="10 0 0 0"
                       VerticalAlignment="Center"
                       Text="Date:" />

            <DatePicker Grid.Row="0"
                        Grid.Column="1"
                        FirstDayOfWeek="Sunday"
                        Text="{Binding CurrentlySelectedOutcomeInput.Date,
                                       ConverterCulture=he-IL,
                                       Mode=TwoWay}" />
            <TextBlock Grid.Row="1"
                       Grid.RowSpan="2"
                       Margin="10 0 0 0"
                       VerticalAlignment="Center"
                       Text="Comment:" />

            <TextBox Name="tbComment"
                     Grid.Row="1"
                     Grid.Column="1"
                     Grid.ColumnSpan="3"
                     Margin="0,0,128,0"
                     MaxLength="4000"
                     Style="{StaticResource textBoxInError}"
                     Text="{Binding CurrentlySelectedOutcomeInput.Comment,
                                    Mode=TwoWay,
                                    UpdateSourceTrigger=PropertyChanged,
                                    ValidatesOnDataErrors=True,
                                    NotifyOnValidationError=True}"
                     TextWrapping="Wrap"
                     Validation.ErrorTemplate="{StaticResource validationTemplate}" />
            <TextBlock Grid.Row="3"
                       Margin="10 0 0 0"
                       VerticalAlignment="Center"
                       Text="Amount:" />
            <TextBox Name="tbAmount"
                     Grid.Row="3"
                     Grid.Column="1"
                     VerticalAlignment="Center"
                     MaxLength="15"
                     Style="{StaticResource textBoxInError}"
                     Text="{Binding CurrentlySelectedOutcomeInput.Amount,
                                    Mode=TwoWay,
                                    UpdateSourceTrigger=PropertyChanged,
                                    ValidatesOnDataErrors=True,
                                    NotifyOnValidationError=True}"
                     Validation.ErrorTemplate="{StaticResource validationTemplate}" />
            <TextBlock Grid.Row="4"
                       Margin="10 0 0 0"
                       VerticalAlignment="Center"
                       Text="Type:" />
            <ComboBox Grid.Row="4"
                      Grid.Column="1"
                      DisplayMemberPath="Type"
                      IsSynchronizedWithCurrentItem="True"
                      ItemsSource="{Binding Path=ActionOutcomeTypes,
                                            Mode=TwoWay}"
                      SelectedValue="{Binding Path=CurrentlySelectedOutcomeInput.ActionTypeId,
                                              Mode=TwoWay}"
                      SelectedValuePath="Id"
                      ToolTip="Action Type" />

            <TextBlock Grid.Row="5"
                       Grid.Column="0"
                       Margin="10 0 0 0"
                       VerticalAlignment="Center"
                       Text="Actions:" />
            <Button Grid.Row="5"
                    Grid.Column="1"
                    Height="25"
                    Command="{Binding CleanOutcomeInputCommand}"
                    Content="Clean input" />
            <Button Grid.Row="5"
                    Grid.Column="2"
                    Height="25"
                    Command="{Binding AddOutcomeRowCommand}"
                    Content="Add Row" />
            <Button Grid.Row="5"
                    Grid.Column="3"
                    Height="25"
                    Command="{Binding DeleteOutcomeRowCommand}"
                    Content="Delete Row" />
            <Button Grid.Row="5"
                    Grid.Column="4"
                    Height="25"
                    Command="{Binding UpdateOutcomeRowCommand}"
                    Content="Update Row" />

        </Grid>

    </Grid>
</UserControl>
